package io.renren.modules.neo4j.controller;

import io.renren.common.utils.R;
import io.renren.modules.neo4j.entity.node.UseNeo;
import io.renren.modules.neo4j.entity.node.course;
import io.renren.modules.neo4j.entity.node.knowledge;
import io.renren.modules.neo4j.entity.node.occupation;
import io.renren.modules.neo4j.respository.KnowledgeRespository;
import io.renren.modules.neo4j.service.CourseNeoService;
import io.renren.modules.neo4j.service.OccupationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("api/neo/course")
public class CourseNeoController {

    @Autowired
    private CourseNeoService courseService;
    @Autowired
    private OccupationService occupationService;

    @Autowired
    private KnowledgeRespository knowledgeRespository;

    @RequestMapping(path = "/addCourse", method = RequestMethod.POST)
    public course addCourse(@RequestBody course course) {
        return courseService.addCourse(course);
    }


    @RequestMapping(path = "/getUserNodeList", method = RequestMethod.GET)
    public course getPerson(@Param("name") String name) {
        return courseService.getCourseByName(name);
    }

    @RequestMapping(path = "/deleteCourse", method = RequestMethod.POST)
    public boolean deleteCourse(@RequestBody Long id) {
        return courseService.deleteCourseById(id);
    }

    @RequestMapping(path = "/findAll", method = RequestMethod.GET)
    public Object findAll(){
        return courseService.findAll();
    }

    @RequestMapping(path = "/findShip", method = RequestMethod.GET)
    public List<Object> findShip(String name){
        return courseService.findShip(name);
    }


    @RequestMapping(path = "/findCourseByoccuoationId", method = RequestMethod.GET)
    public R findCourseByoccuoationId(Long id){
      Map map=  occupationService.findCourseByoccuoationId(id);
        return R.ok().put("data",map);

    }

    @GetMapping("getKnowledgeByCourseId")
    public R getKnowledgeByCourseId(Long id){
        course o=courseService.getKnowledgeByCourseId(id);
        return R.ok("",100).put("data",o);
    }

    @GetMapping("getOccAndCourseAndKnowledge")
    public R getOccAndCourseAndKnowledge(Long id){
        Map map = occupationService.getOccAndCourseAndKnowledge(id);
        return R.ok("",100).put("data",map);

    }


    /**
     * 添加课程下知识点
     * @param useNeo
     * @return
     */
    @PostMapping("saveKnowledgeInCourse")
    public R saveKnowledgeInCourse(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.saveKnowledgeInCourse(startName,endName);

        return R.ok("ok",100);
    }


    /**
     * 删除课程下知识点
     * @param useNeo
     * @return
     */
    @PostMapping("delKnowledgeInCourse")
    public R delKnowledgeInCourse(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.delKnowledgeInCourse(startName,endName);
        return R.ok("ok",100);
    }


    /**
     * 同一课程下的课程创建先后关系
     * @param useNeo
     * @return
     */
    @PostMapping("saveOneCourseKnowledgeShip")
    public R saveOneCourseKnowledgeShip(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.saveOneCourseKnowledgeShip(startName,endName);
        return R.ok("ok",100);
    }


    /**
     * 非同一课程下知识点添加关系
     * @param useNeo
     * @return
     */
    @PostMapping("saveNoOneCourseKnowledgeShip")
    public R saveNoOneCourseKnowledgeShip(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.saveNoOneCourseKnowledgeShip(startName,endName);
        return R.ok("ok",100);
    }


    /**
     * 删除同一课程下两知识点之间的关系
     * @param useNeo
     * @return
     */
    @PostMapping("delCourseKnowledgeShip")
    public R delCourseKnowledgeShip(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.delCourseKnowledgeShip(startName,endName);
        return R.ok("ok",100);
    }





    /**
     * 创建知识点下的节点
     * @param useNeo
     * @return
     */
    @PostMapping("saveLearnInKnowledge")
    public R saveLearnInKnowledge(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        String path = useNeo.getPath();
        int type = useNeo.getType();
        int index = useNeo.getIndex();
        knowledgeRespository.saveLearnInKnowledge(path,type,index,startName,endName);
        return R.ok("ok",100);
    }

    /**
     * 删除知识点下的节点信息
     * @param useNeo
     * @return
     */
    @PostMapping("delLearnInKnowledge")
    public R delLearnInKnowledge(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.delLearnInKnowledge(startName,endName);
        return R.ok("ok",100);
    }


    /**
     * 创建同一知识点下节点信息先后关系
     */
    @PostMapping("saveLearnShip")
    public R saveLearnShip(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.saveLearnShip(startName,endName);
        return R.ok("ok",100);
    }

    /**
     * 删除同一知识点下节点信息先后关系
     */
    @PostMapping("delLearnShip")
    public R delLearnShip(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.delLearnShip(startName,endName);
        return R.ok("ok",100);
    }


    /**
     * 创建不同知识点下节点信息先后关系
     */
    @PostMapping("saveNoSimpleKnowledgeLearnShip")
    public R saveNoSimpleKnowledgeLearnShip(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.saveNoSimpleKnowledgeLearnShip(startName,endName);
        return R.ok("ok",100);
    }



    /**
     * 删除不同知识点下节点信息先后关系
     */
    /*@PostMapping("delNoSimpleKnowledgeLearnShip")
    public R delNoSimpleKnowledgeLearnShip(@RequestBody UseNeo useNeo){
        String startName = useNeo.getStartName();
        String endName = useNeo.getEndName();
        knowledgeRespository.delNoSimpleKnowledgeLearnShip(startName,endName);
        return R.ok("ok",100);
    }
    */
}
